package kr.co.doriclassic.powerjava.chapter12;

import java.util.Arrays;
import java.util.Comparator;


class Students{
	private String name;
	private int id;
	public Students(String name, int id) {
		this.name = name;
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public int getId() {
		return id;
	}
	@Override
	public String toString() {
		return String.format("Students [name=%s, id=%s]", name, id);
	}	
	
	

}
public class SortTest2{
	

	public static void main(String[] args) {
		Students[] arrStu = new Students[5];
		arrStu[0]=new Students("이성계", 3);
		arrStu[1]=new Students("박찬호", 2);
		arrStu[2]=new Students("나경은", 1);
		arrStu[3]=new Students("신한욱", 5);
		arrStu[4]=new Students("김태희", 6);
		
		//익명 클래스 참조, 모두 가능
		Comparator<Students> compName = new Comparator<Students>() {

			@Override
			public int compare(Students o1, Students o2) {
				// TODO Auto-generated method stub
				return o1.getName().hashCode()-o2.getName().hashCode();
			}
		};
		
		Arrays.sort(arrStu, compName);
		prnArr(arrStu);
	}
	
	public static void prnArr(Students[] arr){
		for (Students s : arr) {
			System.out.println(s);
		}
	}
	
	//인터페이스 참조, 정수형만 리턴
	/*@Override
	public int compareTo(Students o) {
		// TODO Auto-generated method stub
		return 0;
	}*/
	
	
}
